package jmine.tec.datadigester.web.pages.importacao;

import jmine.tec.executionlog.domain.ExecutionLogItem;

import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.MarkupStream;
import org.apache.wicket.markup.html.WebComponent;
import org.apache.wicket.markup.transformer.XsltTransformer;

/**
 * @author wagner
 */
public class XsltTransformedExecutionLogItem extends WebComponent {
    private final String xslFilePath;

    private final String executionLogItemContent;

    /**
     * C'tor.
     * 
     * @param id id do componente.
     * @param xslFilePath file path
     * @param executionLogItem {@link ExecutionLogItem}.
     */
    public XsltTransformedExecutionLogItem(String id, String xslFilePath, ExecutionLogItem executionLogItem) {
        super(id);
        this.xslFilePath = xslFilePath;
        this.executionLogItemContent = executionLogItem.getContent();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag) {
        try {
            this.replaceComponentTagBody(markupStream, openTag,
                    new XsltTransformer(this.xslFilePath).transform(this, this.executionLogItemContent));
        } catch (Exception e) {
            this.error(e.getMessage());
        }
    }
}
